﻿using Org.BouncyCastle.Crypto.Tls;
using System;
using System.Collections.Generic;
using System.Text;

namespace AppMain
{
    public class RoleMgr : Singleton<RoleMgr>
    {
        private Dictionary<long, IRole> map = new Dictionary<long, IRole>();

        public void removeRole(IRole role)
        {
            if (role.UID > 0)
            {
                SceneMgr.Instance.removeRole(role);
                if (map.ContainsKey(role.UID))
                {
                    map.Remove(role.UID);
                    role.dispose();
                }
            }
        }

        public void addRole(BaseRole role)
        {
            if (role.UID > 0)
            {
                if (!map.ContainsKey(role.UID))
                {
                    map.Add(role.UID, role);
                }
            }
        }

        public T getRole<T>(long roleId) where T : BaseRole
        {
            IRole role;
            if (map.TryGetValue(roleId, out role))
            {
                return role as T;
            }
            return null;
        }

        public Dictionary<long, IRole>.Enumerator getMapEnumerator()
        {
            return this.map.GetEnumerator();
        }

    }

}
